import  sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class MdiDemo(QMainWindow):
    count = 0

    def __init__(self,parent=None):
        super(MdiDemo,self).__init__(parent)
        self.mdi=QMdiArea()
        self.setCentralWidget(self.mdi)
        bar=self.menuBar()
        file=bar.addMenu("File")
        file.addAction("New")
        file.addAction("save")
        file.addAction("quit")
        file.triggered.connect(self.windowaction)
        self.setWindowTitle("MDI demo")
    def windowaction(self,q):
        if q.text()=="New":

            MdiDemo.count=MdiDemo.count+1
            sub=QMdiSubWindow()
            sub.setWidget(QTextEdit())
            sub.setWindowTitle("subwindow"+str(MdiDemo.count))
            self.mdi.addSubWindow(sub)
            sub.show()
        if q.text()=="save":
            self.mdi.cascadeSubWindows()
        if q.text()=="quit":
            self.mdi.tileSubWindows()


if __name__ == '__main__':
    app=QApplication(sys.argv)
    demo=MdiDemo()

    demo.show()
    sys.exit(app.exec_())
